import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import Components from 'unplugin-vue-components/vite'
import {NaiveUiResolver} from 'unplugin-vue-components/resolvers'
import AutoImport from 'unplugin-auto-import/vite'
import UnoCSS from 'unocss/vite'
import presetWind4 from '@unocss/preset-wind4'

export default defineConfig({
    presets: [
        presetWind4(),
    ],
    plugins: [
        vue(),
        UnoCSS(),
        Components({
            resolvers: [NaiveUiResolver()]
        }),
        AutoImport({
            imports: [
                'vue',
                'vue-router',
                'pinia'
            ]
        })
    ],
    publicDir: 'public',
    resolve: {
        alias: {
            '@': path.resolve(__dirname, 'src')  // 关键点：要用绝对路径
        }
    },
    server: {
        port: 8200,
        open: true,
        proxy: {
            '/api': {
                target: 'http://localhost:8201',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api/, '')
            }
        }
    }
})
